<!DOCTYPE html>
<html>

	<head>
		<title>消息界面</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
		<link rel="stylesheet" href="/css/reset.css"/>
		<link rel="stylesheet" href="/css/travelContent.css"/>
		<link rel="stylesheet" href="/js/plugins/comments-master/css/index.css">
		<link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
		<script src="/js/plugins/jrender/jrender.js"></script>
		<script src="/js/common.js"></script>
		<script src="/js/plugins/dialog/dialog.min.js"></script>

		<script>
			$(function () {
                //拿到当前登录的用户
                //拿到当前登录的用户，要求必须登录之后才能评论
                var currentuser ;
                currentuser = JSON.parse(sessionStorage.getItem("user"));
                //拿到地址栏上面的type
                var type = getParams().type;
                if(type==2){
                    //拿到type和当前用户的id，发送get请求
                    $.get("/users/"+currentuser.id+"/mymessagerelations/comments/travel",{type:type},function (data) {
                        console.log(data);
                        // 拿到数据，然后渲染
                        $("#travel").renderValues({list:data}, {
                            userHandler: function (ele, value) {
                                ele.href = "/userProfiles.html?id=" + value;
                            },
                            travelHandler:function (ele,value) {
                                ele.href="/travelContent.html?id="+value;
                            },
                            messageId:function (ele, value) {
								$(ele).attr("data-id",value);
                            }
                        })
                    })
                }

                if(type==2){
                    //获取用户评论的回复
                    $.get("/users/"+currentuser.id+"/mymessagerelations/comments/comments",{type:type},function (data) {
                        console.log(data);
                        // 拿到数据，然后渲染
                        $("#comments").renderValues({list:data}, {
                            userHandler: function (ele, value) {
                                ele.href = "/userProfiles.html?id=" + value;
                            },
                            messageId:function (ele, value) {
                                $(ele).attr("data-id",value);
                            }
                        })
                    })
				}
                //给已读按钮绑定点击事件
                $("#comments").on("click",".deleteBtn",function () {
                    //拿到按钮上面的Id,删除我的信息表中的数据
					$.ajax({
						url:"/mymessagerelation/"+$(this).data("id"),
						type:"DELETE"
					})
                    window.location.reload();
                })
                //给已读按钮绑定点击事件
                $("#travel").on("click",".deleteBtn",function () {
                    //拿到按钮上面的Id,删除我的信息表中的数据
					$.ajax({
						url:"/mymessagerelation/"+$(this).data("id"),
						type:"DELETE"
					})
                    window.location.reload();
                })

            })



		</script>
	</head>

	<body>
		<div class="search-head">
			<div class="row nav-search">
				<div class="col">
					<a href="javascript:history.go(-1);">
						<span><i class="fa fa-chevron-left" ></i></span>
					</a>
				</div>
				<div class="col">
					<span>我的消息界面</span>
				</div>
				<div class="col"></div>
			</div>
		</div>
		<div class="row dynamic " id="travel">
			<div class="col" render-loop="list">
				<div class="Marquee">
					<div class="d-flex">
						<a render-key="list.currentuser.id" render-fun="userHandler">
							<img class="rounded-circle dynamic-head" render-src="list.currentuser.headImgUrl" width="80px">
						</a>
						<a class="dynamic-detail" render-key="list.travel.id" render-fun="travelHandler">
							<span render-html="list.currentuser.nickName"></span>
							<span>评论了游记：</span>
							<p render-html="list.travel.title"></p>
							<span>评论时间：</span>
							<p render-html="list.comment.creatTimeMsg"></p>
							<span>评论内容：</span>
							<p render-html="list.comment.content"></p>
						</a>
					</div>
					<input type="button" class="deleteBtn" render-key="list.id" render-fun="messageId" value="已读">
				</div>
			</div>
		</div>
		<div class="row dynamic " id="comments">
			<div class="col" render-loop="list">
				<div class="Marquee">
					<div class="d-flex">
						<a render-key="list.currentuser.id" render-fun="userHandler">
							<img class="rounded-circle dynamic-head" render-src="list.currentuser.headImgUrl" width="50px">
						</a>
							<span render-html="list.currentuser.nickName"></span>
							<span>回复时间：</span>
							<p render-html="list.childComment.creatTimeMsg"></p>
							<span>回复内容：</span>
							<p render-html="list.childComment.content"></p>
					</div>
					<input type="button" class="deleteBtn" render-key="list.id" render-fun="messageId" value="已读">
				</div>
			</div>
		</div>


	</body>

</html>